package com.itqf.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/9/23
 * @Time: 下午3:22
 */
public class MyBatisUtils {

    static SqlSession sqlSession;


    static{
            try {
            //1.读mybatis的配置文件  返回InputStream
            InputStream inputStream =  Resources.getResourceAsStream("mybatisConfig.xml");
            //2.SqlSessionFactory   SessionFactory(hibernate)
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            //3.SqlSession    Connection   Session(hibernate)
              sqlSession = sqlSessionFactory.openSession();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }



    public static SqlSession getSqlSession(){
       return  sqlSession;
    }







}
